var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (t) {
  return typeof t;
} : function (t) {
  return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
},
app = getApp(), dataheith = [0], linheightid = 0;
let $this;
var that;
Page({
  data: {
    category:[],
    cika:[],
    rgihtdata: [],
    sub_cat_list_scroll_top: 0,
    store: {
      cat_style: 4
    },
    compId:'',
    tab_config: [],
    linheightid: linheightid,
    scroll: "scroll",
    banner:[]
  },
  // 获取banner
  getIndexBanner: function (res) {
    var $this = this;
    app.getData({
      url: app.api.getIndexBanner() + `?shopId=${wx.getStorageSync('shopData').id}&page=${1}&rows=${3}&adCategory=${2}`,
      method: 'GET',
      // data: {
      //   shopId: wx.getStorageSync('shopData').id,
      //   page: 1,
      //   rows: 3,
      //   adCategory:2
      // },
      ok: function (res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            $this.setData({
              banner: res.data.list,
            });
            // this.tab_config = res.data.data

          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }
    })
  },
  onLoad:function(t){
    $this=this;
  },
  onShow: function () {
    // this.reLoad();
    this.getIndexBanner();
    var shopData = wx.getStorageSync('shopData')
    console.log(shopData)
    var compId = shopData.companyId
    this.setData({
      compId:compId
    })
    that=this
    app.getData({
      url: app.api.getPackageData(1, 0, compId),
      method:'POST',
      ok:function(res){
        console.log(res)
        if (res.statusCode == 200 && res.errMsg =='request:ok'){
          if (res.data.code==1){
            that.setData({
              tab_config: res.data.data
            })
          }else{
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }

    });
    
    that.getCardData()
    
  },
  catItemClick: function (t) {
    console.log(t)
    var e = this;
    console.log("你点击的ID为：", t.currentTarget.dataset.index);
    var o = t.currentTarget.dataset.index;
    console.log(void 0 === o ? "undefined" : _typeof(o)),
      this.setData({
        intoid: "id" + o,
        linheightid: o,
        scroll: ""
      }),
      setTimeout(function () {
        e.setData({
          scroll: "scroll"
        });
      }, 500);
  },
  scroll: function (t) {
    console.log(t);
    for (var e = t.detail.scrollTop, o = (t.detail.scrollTop, 0); o < dataheith.length; o++) if (e <= dataheith[o - 1]) {
      if (console.log(o), console.log(e, linheightid), linheightid != o) {
        if (this.updateSelectedPage(o - 2), -1 == (linheightid = o - 2)) return void this.setData({
          linheightid: 0
        });
        this.setData({
          linheightid: linheightid
        });
      }
      break;
    }
  },
  scroll: function (t) {
    console.log(t);
    for (var e = t.detail.scrollTop, o = (t.detail.scrollTop, 0); o < dataheith.length; o++) if (e <= dataheith[o - 1]) {
      if (console.log(o), console.log(e, linheightid), linheightid != o) {
        if (this.updateSelectedPage(o - 2), -1 == (linheightid = o - 2))
          return void this.setData({
          linheightid: 0
        });
        this.setData({
          linheightid: linheightid
        });
      }
      break;
    }
  },
  updateSelectedPage: function (t) {
    // console.log("====_updateSelectedPage", t);
    var e = this.data, 
    o = e.window_height, 
    i = e.tab_config, 
    a = (i.item_width, Math.round(o / i.item_height)), 
    n = i.item_height * (t - a + 1), l = i.item_height * t;
    console.log(e,o,i,a,n)
    (i.tab_left < n || i.tab_left > l) && (i.tab_left = l - (o - i.item_height) / 2),
      console.log(i), 
      this.setData({
        tab_config: i
      });
  },
  onPullDownRefresh: function () {
    dataheith = [linheightid = 0], this.setData({
      intoid: "id" + linheightid,
      linheightid: linheightid
    }), this.reLoad(), setTimeout(function () {
      wx.stopPullDownRefresh();
    }, 1e3);
  },

  //次卡
  getCardData: function (res) {
    that=this
    app.getData({
      url: app.api.getCika(),
      method: 'GET',
      data: {
        companyId: that.data.compId,
        page: 1,
        rows: 3
      },
      ok: function (res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            console.log(res.data.list)
            that.setData({
              cika: res.data.list,
            });


          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }
    })
  },
  toCardDetail: function (res) {
    console.log(res)
    wx.navigateTo({
      url: '../../index/pages/cardCenter/cardCenterDetail/cardCenterDetail?id=' + res.currentTarget.dataset.item
    })
  }
});